﻿using System;
using SharpKit.JavaScript;

namespace SharpKit.Onx
{
    /// <summary>
    /// Schedules callbacks for execution at a specific time, once, or repeating every given internal.
    /// https://www.onx.ms/#apiPage/scheduler
    /// </summary>
    [JsType(Mode = JsMode.Prototype, Export = false)]
    public class Scheduler : Emitter
    {
        //No way to new this up
        private Scheduler()
        { }

        #region Actions (Methods)
        /// <summary>
        /// Creates a timer for invoking a callback function after a specified time period has elapsed. 
        /// You can specify to invoke the callback only once or repeatedly each time the interval elapses. 
        /// Repeating timers with specific predefined intervals (15min, 30min, hour, halfDay, or day) can be made more efficient by allowing the operating system to batch timers from other applications and to slightly modify the wake-up time.
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="handler"></param>
        public void SetTimer(TimerSettings settings, Action handler)
        { }

        /// <summary>
        /// Removes an alarm
        /// </summary>
        /// <param name="alarmIdentifier">name of alarm to remove</param>
        public void RemoveTimer(string alarmIdentifier)
        { }
        #endregion
    }

    /// <summary>
    /// specifies allowed options for creating the timer
    /// </summary>
    [JsType(JsMode.Json, Export = false)]
    public class TimerSettings
    {
        /// <summary>
        /// the unique name for the alarm (required)
        /// </summary>
        [JsProperty(NativeField = true, Name = "name")]
        public string Name { get; set; }

        /// <summary>
        /// time in milliseconds since Jan-1 1970, specifying when to invoke the callback for the first time.
        /// Time in the past will cause the timer to fire immediately (optional, set to current time by default).
        /// </summary>
        [JsProperty(NativeField = true, Name = "time")]
        public JsNumber Time { get; set; }

        /// <summary>
        /// interval in milliseconds between subsequent invocations of the callback, if specified will create a repeating timer.
        /// can also be one of the following predefined intervals: '15min', '30min', 'hour', 'halfDay', or 'day'.
        /// </summary>
        [JsProperty(NativeField = true, Name = "interval")]
        public object Interval { get; set; }

        /// <summary>
        /// false to enable power optimization for repeating timers with predefined intervals (optional, true by default)
        /// </summary>
        [JsProperty(NativeField = true, Name = "exact")]
        public bool Exact { get; set; }
    }
}